﻿<!DOCTYPE html>
<html>

<head>
    <title>Live block's size</title>
    <meta content="text/html; charset=utf-8" http-equiv="content-type">
    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="../freewall.js"></script>
    <style type="text/css">
        body {
            margin: 0;
            padding: 0;
        }
        article {
            float: left;
            overflow: hidden
        }
        img {
            display: block;
            width: 100%;
            height: auto;
        }
        .for6col article {
            width: 16.66%;
        }
        .for4col article {
            width: 25%;
        }
        .for2col article {
            width: 50%
        }
    </style>
    <script type="text/javascript">

        $(document).ready(function () {

            var gutter = 20;

            function cellSize(containerWidth) {
                if (containerWidth > 1024) {
                    var colNum = 6;
                } else if (containerWidth > 768) {
                    var colNum = 4;
                } else {
                    var colNum = 2;
                }

                return (containerWidth / colNum) - gutter;
            }


            var wall = new Freewall("#freewall");
            wall.reset({
                selector: 'article',
                animate: true,
                cellW: cellSize,
                cellH: 'auto',
                gutterX: gutter,
                gutterY: gutter,
                cacheSize: false,
                onResize: function (container) {
                    var containerWidth = container.width();

                    if (containerWidth > 1024) {
                        container.attr("class", "for6col");
                    } else if (containerWidth > 768) {
                        container.attr("class", "for4col");
                    } else {
                        container.attr("class", "for2col");
                    }

                    wall.fitWidth();

                    document.title = containerWidth;
                }
            });

            wall.fitWidth();

            wall.container.find('.block img').load(function () {
                $(window).trigger("resize");
            });


        });
    </script>
</head>

<body>
    <div id="freewall">
        <article>
            <div class="block">
                <div class="entry-content">
                    <img src="http://lorempixel.com/250/250/animals/" width="250" height="250" />
                </div>
            </div>
        </article>
        <article>
            <div class="block">
                <div class="entry-content">
                    <img src="http://lorempixel.com/250/250/animals/" width="250" height="250" />
                </div>
            </div>
        </article>
        <article>
            <div class="block">
                <div class="entry-content">
                    <img src="http://lorempixel.com/250/250/animals/" width="250" height="250" />
                </div>
            </div>
        </article>
        <article>
            <div class="block">
                <div class="entry-content">
                    <img src="http://lorempixel.com/250/250/animals/" width="250" height="250" />
                </div>
            </div>
        </article>
        <article>
            <div class="block">
                <div class="entry-content">
                    <img src="http://lorempixel.com/250/250/animals/" width="250" height="250" />
                </div>
            </div>
        </article>
        <article>
            <div class="block">
                <div class="entry-content">
                    <img src="http://lorempixel.com/250/250/animals/" width="250" height="250" />
                </div>
            </div>
        </article>
    </div>
</body>

</html>
